Unit CubeΒΆ

Here we show some example of plotting the objects defined on a Unit Cube

import dolfin as df
from fenics_plotly import plot
mesh = df.UnitCubeMesh(3, 3, 3)
plot(mesh)
# plot(mesh, wireframe=False)
<fenics_plotly.fenics_plotly.FEniCSPlotFig at 0x7f2e23e37cd0>
for degree in [2]: 
    V = df.FunctionSpace(mesh, "CG", degree)
    p = df.Function(V)
    p.interpolate(df.Expression("sin(x[0])", degree=1))
    plot(V)
    plot(p, show_grid=True)
    plot(p, scatter=True, wireframe=False)
V = df.VectorFunctionSpace(mesh, "CG",  2)
u = df.Function(V)
u.interpolate(df.Expression(("1 + x[0]*x[0]", "x[1]*x[1]", "x[2]*x[2]") , degree=1))
plot(V)
plot(u, size=1)
#plot(u, normalize=True, size=1)
#plot(u, norm=True, size=1)
<fenics_plotly.fenics_plotly.FEniCSPlotFig at 0x7f2e20caea00>
for component in ["magnitude", "x"]: #, "y", "z"]:
    plot(u, component=component)
fixed = df.CompiledSubDomain("near(x[0], 0) && on_boundary")
free = df.CompiledSubDomain("near(x[0], 1) && on_boundary")

# Create a facet fuction in order to mark the subdomains
ffun = df.MeshFunction("size_t", mesh, 2)
ffun.set_all(0)

# Mark the first subdomain with value 1
fixed_marker = 1
fixed.mark(ffun, fixed_marker)

# Mark the second subdomain with value 2
free_marker = 2
free.mark(ffun, free_marker)

V = df.VectorFunctionSpace(mesh, "CG",  2)
bc = df.DirichletBC(V, df.Constant((0.0, 0.0, 0.0)), fixed)
plot(bc)
<fenics_plotly.fenics_plotly.FEniCSPlotFig at 0x7f2e20d54e80>
plot(ffun, show_grid=True)
<fenics_plotly.fenics_plotly.FEniCSPlotFig at 0x7f2e20b56f10>
cfun = df.MeshFunction("size_t", mesh, 3)
cfun.set_all(1)
tol=1e-14
left = df.CompiledSubDomain("x[0] <= 0.5 + tol", tol=tol)
right = df.CompiledSubDomain("x[0] >= 0.5 - tol", tol=tol)
left_marker = 1
#left.mark(cfun, left_marker)
    
right_marker = 2
right.mark(cfun, right_marker)
plot(cfun)#, scatter=True)
<fenics_plotly.fenics_plotly.FEniCSPlotFig at 0x7f2e20b79fd0>